/********************************************************/
/*	Copyright (C) 2016 Gong Li Bin		 	*/
/*	Project:	GlbRtbEng-1.0.0			*/
/*	Author:		gong_libin			*/
/*	Date:		2016_06_26			*/
/*	File:		GlbRtbAdvs.h			*/
/********************************************************/

#ifndef	_GLBRTBADVS_H
#define	_GLBRTBADVS_H

#include "GlbRtbBase.h"

#include <libxml/tree.h>
#include <libxml/parser.h>

/* GlbRtbAdvs */
#define	GLB_RA_KEY				'A'
#define	GLB_RA_PATH				(char*)"/usr/local/bin"

#define	GLB_RA_SUM				1000
#define	GLB_RA_SIZE				sizeof(GLBRAINFO_S)

typedef struct tagGlbRaInfo
{
	char m_szAdId[GLB_BYTE128];		// policyID
	char m_szBgTm[GLB_BYTE128];		// start time
	char m_szEdTm[GLB_BYTE128];		// end time
	char m_szBrow[GLB_BYTE128];		// browser
	char m_szOsNm[GLB_BYTE128];		// os name
	char m_szMdTy[GLB_BYTE128];		// mediatype
	char m_szMedi[GLB_BYTE128];		// media
	char m_szPrio[GLB_BYTE128];		// priority
	char m_szVolu[GLB_BYTE128];		// volume
	char m_szPric[GLB_BYTE128];		// price
	char m_szSrcn[GLB_BYTE128];		// screen
	char m_szType[GLB_BYTE128];		// type
	char m_szCUrl[GLB_KBYTES2];		// curl
	char m_szLoca[GLB_KBYTES8];		// location
}GLBRAINFO_S;

class CGlbRtbAdvs : public CGlbRtbBase
{
public:
	CGlbRtbAdvs() {}
	virtual ~CGlbRtbAdvs() {}

	void GlbRtbAdvsDisplay();

	virtual void GlbRtbBaseCount();
	virtual int GlbRtbBaseInput(void* pPara);

protected:

private:

};

inline int GlbRtbAdvsComp(const void* pFirst, const void* pSecond)
{
	return strcmp(((GLBRAINFO_S*)pFirst)->m_szAdId, ((GLBRAINFO_S*)pSecond)->m_szAdId);
}

void GlbRtbAdvsPrint(GLBRAINFO_S* pstInfo);
void GlbRtbAdvsParse(xmlNode* pstNode, GLBRAINFO_S* pstInfo);

/* GlbRtbXml */
#define	GLB_RA_NAME(P)				(char*)P->name
#define	GLB_RA_CONT(P)				(char*)P->children->content
#define	GLB_RA_TYPE(P)				XML_ELEMENT_NODE == P->type

#define	GLB_RA_LOOPEND				}
#define	GLB_RA_LOOP(P, C)			for (C = P->children; NULL != C; C = C->next) {

typedef struct tagGlbRaNode
{
	char* m_pszKey;
	char* m_pszVal;
}GLBRANODE_S;

inline void GlbRaXmlClean()
{
	xmlCleanupParser();

	return;
}

inline void GlbRaXmlFree(xmlDoc* pstDoc)
{
	xmlFreeDoc(pstDoc);

	return;
}

inline xmlDoc* GlbRaXmlFile(char* pszFile)
{
	return 	xmlParseFile(pszFile);
}

inline xmlNode* GlbRaXmlRoot(xmlDoc* pstDoc)
{
	return 	xmlDocGetRootElement(pstDoc);
}

inline void GlbRaXmlVal(xmlNode* pstNode, char* pszVal)
{
	strcpy(pszVal, GLB_RA_CONT(pstNode));

	return;
}

#endif /* _GLBRTBADVS_H */
